//
//  HUD+Toast.swift
//  BWHUDKit
//
//  Created by zhuxuhong on 2022/3/21.
//

import UIKit


extension HUD {
    public static func toast(
        _ text: String,
        duration: TimeInterval = 0
    ) {
        show(.toast(.init(icon: nil, text: text, customView: nil, duration: duration)))
    }
    
    public static func toast(
        icon: Toast.Icon?,
        text: String?,
        duration: TimeInterval = 0
    ) {
        show(.toast(.init(icon: icon, text: text, customView: nil, duration: duration)))
    }
    
    public static func toast(
        customView: UIView,
        duration: TimeInterval = Duration.short
    ) {
        show(.toast(.init(icon: nil, text: nil, customView: customView, duration: duration)))
    }
}


extension HUD {
    public class Toast: Data {
        public typealias Icon = Snack.Icon
        
        public init(
            icon: Icon? = nil,
            text: String? = nil,
            customView: UIView? = nil,
            duration: TimeInterval = 0,
            position: ShowPosition = .bottom
        ) {
            let d = duration>0 ? duration : Duration.fit(text: text)
            super.init(icon: icon?.image, text: text, customView: customView, duration: d, maskColor: .clear, blockable: false, position: position)
        }
    }
}
